Skip to content

fix(security): disable docker-postgres on kyber - #1506

Merged
shunkakinoki merged 5 commits into
mainfrom
twinkly-dazzling-stroustrup
Apr 18, 2026
Merged

fix(security): disable docker-postgres on kyber#1506
shunkakinoki merged 5 commits into
mainfrom
twinkly-dazzling-stroustrup

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Apr 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Postgres container on kyber was compromised via public 0.0.0.0:5432 with trust auth, running a cryptominer as /tmp/mysql
  • Inverts docker-postgres enable condition: now only runs on galactica and matic, not kyber
  • Compromised container already stopped and removed

Test plan

  • Verify kyber home-manager switch no longer creates docker-postgres systemd service
  • Verify galactica/matic still get docker-postgres service

Summary by cubic

Disable docker-postgres on kyber to prevent reinfection; the service now runs only on galactica and matic. Also extracted secure-dotenv into a script with tests and switched CI Docker cache to the registry for stability.

  • Bug Fixes

    • Inverted enable condition in home-manager/services/docker-postgres: enabled only on galactica/matic.
    • Stopped and removed the compromised container that was exposed on 0.0.0.0:5432 with trust auth.
  • Refactors

    • Moved secure-dotenv logic to home-manager/modules/secure-dotenv/secure-dotenv.sh and call it from activation with the home dir; uses Nix var substitution for find/stat.
    • Added spec/secure_dotenv_spec.sh and coverage checks; minor shfmt/nixfmt fixes and small cleanups (ollama args, mempalace module).
    • CI: switched .github/workflows/docker.yml cache from GHA to registry-based cache-from/cache-to to avoid auth timeouts.

Written for commit 83525b0. Summary will update on new commits.

shunkakinoki and others added 4 commits April 18, 2026 10:13
…lures

- Extract inline writeShellScript in secure-dotenv to external .sh file
- Fix nixfmt drift in ollama/default.nix (multi-line args)
- Fix shfmt drift in clipboard_copy_spec.sh (here-string spacing)
- Switch Docker cache from GHA to registry-based to avoid auth timeout
@mesa-dot-dev

mesa-dot-dev Bot commented Apr 18, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@shunkakinoki
shunkakinoki merged commit 0fb9560 into main Apr 18, 2026
21 of 27 checks passed
@coderabbitai

coderabbitai Bot commented Apr 18, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 423c3e5d-c968-4a89-ae55-4f551ce406ce

📥 Commits

Reviewing files that changed from the base of the PR and between ca51ec1 and 83525b0.

📒 Files selected for processing (9)
  • .github/workflows/docker.yml
  • config/mempalace/default.nix
  • home-manager/modules/secure-dotenv/default.nix
  • home-manager/modules/secure-dotenv/secure-dotenv.sh
  • home-manager/services/docker-postgres/default.nix
  • home-manager/services/ollama/default.nix
  • spec/clipboard_copy_spec.sh
  • spec/coverage_spec.sh
  • spec/secure_dotenv_spec.sh

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added comprehensive test suite for environment file permission management.
  • Improvements

    • Optimized Docker build caching with per-architecture registry-backed cache for faster builds.
    • Refined environment file security script execution with improved parameterization and Bash invocation.
  • Chores

    • Updated docker-postgres service to enable only on specific host configurations.

Walkthrough

Updated Docker build caching to use GHCR registry-backed layer caches per architecture, refactored secure-dotenv module to use external shell script with Bash invocation, adjusted service enablement conditions, and added comprehensive test coverage for the secure-dotenv functionality.

Changes

Cohort / File(s) Summary
Docker Build Configuration
.github/workflows/docker.yml
Switched from GitHub Actions cache to GHCR registry-backed build cache, keyed per target architecture via matrix.build.arch. Changed cache-from: type=gha to cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ matrix.build.arch }} with corresponding cache-to update.
Nix Module Parameter Updates
config/mempalace/default.nix, home-manager/services/ollama/default.nix
Updated function signatures: mempalace changed variadic argument to underscore parameter; ollama reformatted multi-line parameter list. Both preserve bound parameters and logic.
Service Enablement Logic
home-manager/services/docker-postgres/default.nix
Flipped enabled condition from requiring both isGalactica and isMatic to be false, to requiring at least one to be true. Affects conditional service instantiation.
Secure-dotenv Script Refactoring
home-manager/modules/secure-dotenv/default.nix, home-manager/modules/secure-dotenv/secure-dotenv.sh
Extracted inline shell script generation into external secure-dotenv.sh template via pkgs.replaceVars. Changed invocation to explicit Bash execution with homeDir passed as command-line argument instead of direct script execution.
Test Suite Additions & Updates
spec/clipboard_copy_spec.sh, spec/coverage_spec.sh, spec/secure_dotenv_spec.sh
Added new comprehensive test suite for secure-dotenv.sh validating permission fixes, symlink handling, depth limiting, and script properties. Updated coverage checks to include new spec. Minor whitespace fix in clipboard test heredoc syntax.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

bug

Poem

🐰 Hop, hop! The cache now lives in GHCR's keep,
Per-arch builds with secrets buried deep,
Dotenv scripts externalized, neat and trim,
Permissions fixed—no permission whim!
Tests hopping through each case with care.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch twinkly-dazzling-stroustrup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@shunkakinoki
shunkakinoki deleted the twinkly-dazzling-stroustrup branch April 18, 2026 17:47
…r reinfection

Postgres container was compromised via public 0.0.0.0:5432 binding with trust auth.
Invert the enable condition so docker-postgres only runs on galactica and matic.
@mesa-dot-dev

mesa-dot-dev Bot commented Apr 18, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Disabled docker-postgres on kyber due to a security compromise, inverting its enable condition to run only on galactica and matic.

What changed?

  • Postgres container on kyber was compromised via public 0.0.0.0:5432 with trust auth, running a cryptominer as /tmp/mysql
  • Inverts docker-postgres enable condition: now only runs on galactica and matic, not kyber
  • Compromised container already stopped and removed

Description generated by Mesa. Update settings

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the secure-dotenv module by extracting its shell logic into a separate script file and using pkgs.replaceVars for path substitution. It also corrects the enablement logic for the docker-postgres service and adds a comprehensive test suite for the new script. Feedback was provided to improve the robustness of the file-finding logic in the shell script by using null delimiters to safely handle filenames with special characters.

Comment on lines +7 to +17
@find@ "${HOME_DIR}" \
-maxdepth 4 \
\( -name '.env' -o -name '.env.*' -o -name '*.env' \) \
2>/dev/null | while IFS= read -r f; do
if [ -f "$f" ] && [ ! -L "$f" ]; then
current=$(@stat@ -c '%a' "$f")
if [ "$current" != "600" ]; then
chmod 600 "$f"
fi
fi
done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To robustly handle filenames that might contain spaces or newlines, it is recommended to use -print0 with find and read -d ''. This follows the organization's general rule for robustly parsing command output. Additionally, using -type f in the find command is more efficient and allows removing the manual file type check inside the loop.

Suggested change
@find@ "${HOME_DIR}" \
-maxdepth 4 \
\( -name '.env' -o -name '.env.*' -o -name '*.env' \) \
2>/dev/null | while IFS= read -r f; do
if [ -f "$f" ] && [ ! -L "$f" ]; then
current=$(@stat@ -c '%a' "$f")
if [ "$current" != "600" ]; then
chmod 600 "$f"
fi
fi
done
@find@ "${HOME_DIR}" \
-maxdepth 4 \
-type f \
\( -name '.env' -o -name '.env.*' -o -name '*.env' \) \
-print0 2>/dev/null | while IFS= read -r -d '' f; do
current=$(@stat@ -c '%a' "$f")
if [ "$current" != "600" ]; then
chmod 600 "$f"
fi
done
References
  1. To robustly parse command output in shell scripts, use a unique delimiter (e.g., tab) in the format string and read with a matching IFS. This is safer than splitting by spaces with cut, especially when data fields might contain spaces.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 9 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="spec/secure_dotenv_spec.sh">

<violation number="1" location="spec/secure_dotenv_spec.sh:82">
P2: The `.env` permission test only checks exit status and never asserts the mode changed to `600`, so it can pass even when behavior is broken.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

After 'cleanup'

It 'changes .env from 644 to 600'
When run bash "$PROCESSED_SCRIPT" "$TEST_HOME"

@cubic-dev-ai cubic-dev-ai Bot Apr 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The .env permission test only checks exit status and never asserts the mode changed to 600, so it can pass even when behavior is broken.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At spec/secure_dotenv_spec.sh, line 82:

<comment>The `.env` permission test only checks exit status and never asserts the mode changed to `600`, so it can pass even when behavior is broken.</comment>

<file context>
@@ -0,0 +1,114 @@
+After 'cleanup'
+
+It 'changes .env from 644 to 600'
+When run bash "$PROCESSED_SCRIPT" "$TEST_HOME"
+The status should be success
+End
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant